package com.clwl.supervise.superviseapp.service.base;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.clwl.supervise.superviseapp.entity.base.SysAppUpdate;
import com.clwl.supervise.superviseapp.entity.base.SysFile;
import com.clwl.supervise.superviseapp.mapper.base.SysAppUpdateMapper;
import com.clwl.supervise.superviseapp.mapper.base.SysFileMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 作者姓名:cheny
 * 创建时间:2022/5/18 16:51
 * 说明信息:
 **/
@Service
public class AppUpdateService {

    @Resource
    private SysAppUpdateMapper sysAppUpdateMapper;
    @Resource
    private SysFileMapper sysFileMapper;

    private  String fileUploadActive;

    @Value("${spring.profiles.file_upload_active}")
    public void setFileUploadActive(String fileUploadActive) {
        this.fileUploadActive = fileUploadActive;
    }
    public SysAppUpdate selectTopDateUpdate(String type,String packageType) {
        QueryWrapper<SysAppUpdate> queryWrapper = new QueryWrapper();
        queryWrapper.orderByDesc("version_one", "version_two", "version_three");
        queryWrapper.eq("status", "1");
        queryWrapper.eq("delete_flag", "0");
        if(StringUtils.isNotEmpty(packageType)){
            queryWrapper.eq("PACKAGE_TYPE", packageType);
        }
        if ("ios".equals(type)) {
            queryWrapper.eq("driver_type", "2");//ios
        } else {
            queryWrapper.eq("driver_type", "1");//安卓
        }
        List<SysAppUpdate> sysAppUpdateList = sysAppUpdateMapper.selectList(queryWrapper);
        if (sysAppUpdateList.size() <= 0) {
            return null;
        } else {
            SysAppUpdate sysAppUpdate = sysAppUpdateList.get(0);
            SysFile sysFile = sysFileMapper.selectById(sysAppUpdate.getFileUrl());
            sysAppUpdate.setFileUrl(sysFile.getFilePath().replaceAll("\\\\", "/"));
            sysAppUpdate.setFileUrl(sysAppUpdate.getFileUrl().substring(1));
            return sysAppUpdate;
        }
    }
}

